const fs = require('fs');
let data = '写入数据：';

// 创建写入流
var writerStream = fs.createWriteStream('output.txt');

// 使用 utf8 编码写入数据
writerStream.write(data,'utf-8');

// 标记文件末尾
writerStream.end;

//处理流事件 finish,error
writerStream.on('finish',function () {
    console.log('写入成功！');
});
writerStream.on('error',function(){
    console.log(error.stack);
    console.log('写入失败！');
});
console.log('程序执行完毕！');